#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	int countBattleships(vector<vector<char>>& board)
	{
		int res = 0;
		for (int row = 0, len_row = size(board); row < len_row; row++)
			for (int col = 0, len_col = size(board[0]); col < len_col; col++)
				if (board[row][col] == 'X') {
					res++;
					dfs(board, row, col);
				}

		return res;
	}

private:
	void dfs(vector<vector<char>>& board, int row, int col)
	{
		if (row < 0 || row == size(board) ||
			col < 0 || col == size(board[0]) ||
			board[row][col] == '.') return;

		board[row][col] = '.';
		for (auto [dx, dy] : direct) dfs(board, row + dx, col + dy);
	}

	array<int[2], 4> direct { { { 1, 0 }, { 0, 1 }, { 0, -1 }, { -1, 0 } } };
};

int main()
{
	[[maybe_unused]] Solution solution;
	return 0;
}
